package com.dong.filter.ratelimit;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 限流相关
 **/
public class RemoteAddrKeyResolver implements KeyResolver {
    public static final String BEAN_NAME = "remoteAddrKeyResolver";

    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
    	//根据ip限流相关
        return Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
        //根据请求参数中的 user 字段来限流
//        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user"));
    }

}
